package com.slkj.shilixiaoyuanapp.ui.teacher.tool.OutWork;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.api.InjectParam;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.data.UserRequest;
import com.slkj.shilixiaoyuanapp.entity.ToolOutWorkDetailEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.ui.common.ChosePeopleActivity;
import com.slkj.shilixiaoyuanapp.util.TestDataProvider;
import com.slkj.shilixiaoyuanapp.util.TimeUtils;
import com.slkj.shilixiaoyuanapp.view.NumberEditText;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;

import butterknife.BindView;
import butterknife.OnClick;

@ActivityInfo(layout = R.layout.activity_out_work_dsp, title = "待审批")
public class OutWorkDspActivity extends BaseActivity {

    @InjectParam
    int id;
    @InjectParam
    ToolOutWorkDetailEntity data;
    @BindView(R.id.tv_start_time)
    TextView tvStartTime;
    @BindView(R.id.tv_end_time) TextView tvEndTime;
    @BindView(R.id.tv_spr) TextView tvSpr;
    @BindView(R.id.edit_day)
    EditText editDay;
    @BindView(R.id.edit_where) EditText editWhere;
    @BindView(R.id.edit_content)
    NumberEditText editContent;
    @BindView(R.id.tv_user_name) TextView tvUserName;
    @BindView(R.id.tv_now_day_time) TextView tvNowDayTime;
    @BindView(R.id.tv_cb)
    TextView tvCb;
    @BindView(R.id.iv_select_spr)
    ImageView iv_select_spr;
    @Override
    protected void init() {
        OutWorkDspActivity__JumpCenter.bind(this);

        tvUserName.setText(UserRequest.getInstance().getUser().getUser().getUName());
        tvNowDayTime.setText(data.getInntime());
        editWhere.setText(data.getSite());
        tvStartTime.setText(data.getStartDate());
        tvEndTime.setText(data.getEndDate());
        editDay.setText(String.valueOf(data.getDuration()));
        editContent.setText(data.getBody());
        tvSpr.setText(ChosePeopleActivity.getPeoplesInfos(data.getAuditor()));

        tvCb.setEnabled(!data.isUrge());
        iv_select_spr.setVisibility(View.GONE);
    }
    /**
     * 删除。
     */
    @OnClick(R.id.tv_cx)
    void delete() {
        HttpHeper.get().toolService()
                .toolDelete("Evection/deleteByIdAuditEvection.do", id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(OutWorkDspActivity.this,data);
                        finish();
                    }
                });
    }

    /**
     * 催办
     */
    @OnClick(R.id.tv_cb)
    void cb() {
        HttpHeper.get().toolService()
                .cb(ChosePeopleActivity.getIdList(data.getAuditor()).toString(),id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(OutWorkDspActivity.this,data);
                        tvCb.setEnabled(false);
                    }
                });
    }

}
